package com.contract.controller;

import com.contract.pojo.input.TemplateSaveInput;
import com.contract.pojo.output.JsonResult;
import com.contract.pojo.output.TemplateOutPut;
import com.contract.service.BizTemplateService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 用户controller
 *
 * @author liw
 * @version 1.0
 * @date 2022/8/13 11:10
 */
@ApiOperation("模板")
@RestController
@RequestMapping("contract/template")
public class BizTemplateController {

    @Autowired
    private BizTemplateService bizTemplateService;

    @GetMapping("list")
    @ApiOperation("查询列表")
    @PreAuthorize("hasAuthority('template_list')")
    public JsonResult<List<TemplateOutPut>> queryList(@RequestHeader("token") String token) {
        return bizTemplateService.queryList();
    }

    @GetMapping("info/{id}")
    @ApiOperation("查询详情")
    @PreAuthorize("hasAuthority('template_info')")
    public JsonResult<TemplateOutPut> queryInfo(@RequestHeader("token") String token, @PathVariable("id") Long id) {
        return bizTemplateService.queryInfo(id);
    }

    @PostMapping("info")
    @ApiOperation("查询详情")
    @PreAuthorize("hasAuthority('template_save')")
    public JsonResult<Long> save(@RequestHeader("token") String token, @Valid @RequestBody TemplateSaveInput vo) {
        return bizTemplateService.save(vo);
    }

}
